package info.hexin.jetty;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.webapp.WebAppContext;

import java.io.File;

/**
 * Created by infi.he on 2015/5/6.
 */
public class Main {
    private static final String WAR_PATH = "C:\\creative-java-0.1-SNAPSHOT.war";
    private static final String WORK_PATH = "E:\\tmp\\jettytmp";

    public static void main(String[] args) throws Exception {
        Server server = new Server();
        SelectChannelConnector connector = new SelectChannelConnector();
        connector.setPort(8080);
        connector.setForwarded(true);
        server.addConnector(connector);

        File warFolder = new File(WAR_PATH);
        String warUrl = warFolder.toURI().toURL().toExternalForm();

        WebAppContext context = new WebAppContext();
        context.setWar(warUrl);
        context.setContextPath("/");
        ContextHandlerCollection contexts = new ContextHandlerCollection();
        contexts.addHandler(context);
        File file  = new File(WORK_PATH);
        context.setTempDirectory(file);

        server.setHandler(contexts);
        server.setStopAtShutdown(true);
        server.setSendServerVersion(true);

        server.start();

    }
}
